package com.lsy.wallet.controller;

import com.lsy.wallet.pojo.DealRunningWater;
import com.lsy.wallet.pojo.UserWallet;
import com.lsy.wallet.service.api.DealRunningWaterService;
import com.lsy.wallet.service.api.UserWalletService;
import com.lsy.wallet.vo.ConsumptionVo;
import com.lsy.wallet.vo.RefundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author lsyandwh
 * @create 2023-03-07 17:00
 */
@RestController
@RequestMapping("/wallet")
public class WalletController {

    @Autowired
    private UserWalletService userWalletService;

    @Autowired
    private DealRunningWaterService dealRunningWaterService;

    /**
     * 查询用户钱包余额
     * TODO 用户id应该加密处理
     * @return
     */
    @GetMapping("/get/wallet/detail/{userId}")
    public UserWallet getWalletDetailByUserId(@PathVariable Long userId){

        UserWallet userWallet = userWalletService.getWalletDetailByUserId(userId);

        return userWallet;
    }

    /*
     {
     	"rollOutWalletId":1,
     	"shiftToWalletId":2,
     	"money":100,
     	"payPassword":123456
     }
     */
    /**
     * 用户消费100元的接口
     * @param consumptionVo
     * @return
     */
    @PostMapping("/consumption")
    public String consumption(@RequestBody ConsumptionVo consumptionVo){

        if(null == consumptionVo) throw new RuntimeException("请求非法");

        //返回生成的用户流水单号
        String runningWaterId = dealRunningWaterService.consumption(consumptionVo);

        return runningWaterId;
    }

    /*
    {
	"runningWaterId":"2023030721011812",
	"orderId":"111111111111",
	"refundMoney":20
    }
     */
    /**
     * 用户退款20元接口
     * @return
     */
    @PostMapping("/refund")
    public String refund(@RequestBody RefundVo refundVo){

        if(null == refundVo) throw new RuntimeException("请求非法");

        dealRunningWaterService.refund(refundVo);

        return "退款成功";
    }

    /**
     * 查询用户钱包金额变动明细的接口
     * @param userId
     * @return
     */
    @GetMapping("/get/dealRunningWaterList/{userId}")
    public List<DealRunningWater> getDealRunningWaterList(@PathVariable Long userId){

        List<DealRunningWater> list = dealRunningWaterService.getDealRunningWaterList(userId);

        return list;
    }


}
